<?php
/***************************************************************************
 *                              pirep_update.php
 *                            -------------------
 *                       (APU) Automated Pilot Utility
 *   begin                : Saturday, Jan 21, 2006
 *   copyright            : (C) 2004-2006 SF Games
 *   email                : techsupport@sf-games.com
 *
 *   Expects the following POST variables:
 *
 * 		            Delete PIREP: delete_pirep	- Checkbox to delete this PIREP
 * 		             Flight Date: flight_date	- Was a SQL date format, may need to be checked
 * 		           Aircraft Type: ac_type		-
 * 		             Tail Number: tail_num		-
 * 		           Flight Number: flight_num	-
 * 		  Departure Airport ICAO: departure		-
 * 		Destination Airport ICAO: destination	-
 * 		            Time Out GMT: time_out		-
 * 		             Time In GMT: time_in		-
 * 		   Total Time Fixed Wing: time_fixed	-
 * 		         Total Time Helo: time_helo		-
 * 		            Fuel Out lbs: fuel_out		-
 * 		             Fuel In lbs: fuel_in		-
 * 		         Total Fuel Burn: fuel_burn		-
 * 		           Number of PAX: pax			-
 * 		               Cargo lbs: cargo			-
 * 		         Flight Comments: comments		-
 * 		     Unique PIREP Rec ID: pirepid		-
 ***************************************************************************/

	$apus_root_path = '../include/';
	include($apus_root_path . 'common.php');
	include($apus_root_path . 'config.php');

	// Get the posted variables
	$delete_pirep 	= $_POST['delete_pirep'];
	$flight_date 	= $_POST['flight_date'];
	$ac_type 		= $_POST['ac_type'];
	$tail_num 		= $_POST['tail_num'];
	$flight_num 	= $_POST['flight_num'];
	$departure 		= $_POST['departure'];
	$destination 	= $_POST['destination'];
	$time_out 		= $_POST['time_out'];
	$time_in 		= $_POST['time_in'];
	$time_fixed 	= $_POST['time_fixed'];
	$time_helo 		= $_POST['time_helo'];
	$fuel_out 		= $_POST['fuel_out'];
	$fuel_in 		= $_POST['fuel_in'];
	$fuel_burn 		= $_POST['fuel_burn'];
	$pax 			= $_POST['pax'];
	$cargo 			= $_POST['cargo'];
	$comments 		= $_POST['comments'];
	$pirepid 		= $_POST['pirepid'];

	// Fix the freakin checkbox crap
	if ( $delete_pirep == "" )   $delete_pirep   = "0"; else $delete_pirep   = "1";

	// HTML header
	echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
	echo "<html>\n";
	echo "<head>\n";
	echo "<title>APU Pilot Administration</title>\n";
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
	echo "</head>\n";
	echo "<body>\n";
	echo "<div align=\"center\">\n";
	echo("<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"4\" color=\"#990000\"><b>(APU) Automated Pilot Utility<br>Updating Pilot PIREP</b></font><br><br>\n");

	//
	// Attempt connection to mySQL
	//

	$db = mysql_connect($dbhost, $dbuname, $dbpass)
		or die("Could not connect to the SQL server<br>");
	mysql_select_db($dbname);

	// Check for PIREP delete
	if ( $delete_pirep == 1 )
	{
		// SQL Update the given post vars to given pilotid
		$query = "DELETE FROM " .$table_prefix ."PIREP WHERE id = " .sqlfix($pirepid) ."LIMIT 1";

		// Perform the update query
		$result = mysql_query($query);
		if ( !$result )
			die("Deletion of PIREP record failed.<br>Click your browsers back button to try again.<br>Failed with mySQL error: " . mysql_error());

		echo("<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"3\" color=\"#990000\">Deletion of PIREP Was successful<br>Press the back button to return to the administration page.</font></div><br>\n");
	}
	else
	{
		// SQL Update the given post vars to given pilotid
		//$query = "UPDATE " .$table_prefix ."PILOTS SET FIRST_NAME='$first_name', LAST_NAME='$last_name', EMAIL='$email', RANK_AC='$ac_rank', RANK_HELO='$helo_rank', HOURS_AC='$ac_hours', HOURS_HELO='$helo_hours', TOTAL_HRS='$total_hours', BID='$bid', DART='$dart', SAR='$sar', FLEET_SUP='$fleet_support', LOA='$loa', ACTIVE='$active', JOINED='$join_date', LAST_FLY='$last_fly_date', DELETED='0' WHERE PILOT_ID = " .sqlfix($pilotid);
		$query = "UPDATE " .$table_prefix ."PIREP SET FLIGHT_DATE='$flight_date', AC_TYPE='$ac_type', TAIL_NUM='$tail_num', FLIGHT_NUM='$flight_num', DEPART='$departure', DEST='$destination', TIME_OUT='$time_out', TIME_IN='$time_in', TIME_FIXED='$time_fixed', TIME_HELO='$time_helo', FUEL_OUT='$fuel_out', FUEL_IN='$fuel_in', FUEL_BURN='$fuel_burn', PAX='$pax', CARGO='$cargo', COMMENTS='$comments' WHERE id='$pirepid'";

		// Perform the update query
		$result = mysql_query($query);
		if ( !$result )
			die("Updating of PIREP record failed.<br>Click your browsers back button to try again.<br>Failed with mySQL error: " . mysql_error());

		echo("<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"3\" color=\"#990000\">Update of PIREP Was successful<br>Press your browsers back button to return.</font></div><br>\n");
	}

	// HTML footer
	echo("<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#990000\">" .$APU_COPYRIGHT ."</font></div><br>\n");
	echo "</div>\n";
	echo "</body>\n";
	echo "</html>\n";

?>
